package com.itboye.sunsun.adapter;

import java.util.Iterator;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import com.itboye.sunsun.application.App;
import com.itboye.sunsun.beans.OrderBean.InnerDetailBean;
import com.itboye.sunsun.constants.SPContants;
import com.itboye.sunsun.network.HttpRequest;
import com.itboye.sunsun.person.ui.EmsActivity;
import com.itboye.sunsun.utils.SPUtils;
import com.itboye.sunsun.volley.MyJsonRequest;
import com.itboye.sunsun.volley.XErrorListener;
import com.itboye.sunsun.volley.XRequestListener;

public class WaitReceiveOrderAdapter extends AbstractOrderAdapter {

	public WaitReceiveOrderAdapter(Context context, List<InnerDetailBean> list) {
		super(context, list);
		
	}

	@Override
	public String onGetLeftTextviewText() {
		
		return "查看物流";
	}

	@Override
	public String onGetRightTextviewText() {
		
		return "确认收货";
	}

	@Override
	public void onLeftViewClick(View v) {
		//DebugToast.show("查看物流  "+v.getTag().toString()	, 1);
		searchEms(""+v.getTag().toString());
		//Toast.makeText(App.ctx, v.getTag().toString(), 0).show();

	}

	@Override
	public void onRightViewClick(View v) {
		
		//DebugToast.show("确认收货  "+v.getTag().toString()	, 1);
		confirmOrder(""+v.getTag().toString());
	}
	
	/**
	 * 确认收货
	 * @param 订单号
	 */
	private void confirmOrder(final String orderCode)
	{
		
			MyJsonRequest<String>request=new MyJsonRequest.Builder<String>()
					.typeKey("BY_Orders_sureorder")
					.apiVer("100")
					.param("order_code", orderCode)
					.param("uid", (String)SPUtils.get(context, null, SPContants.USER_ID	, ""))
					.requestListener(new XRequestListener<String>() {
						@Override
						public void onResponse(String arg0) {
							 
							Iterator<InnerDetailBean> itr=list.iterator();
							while ( itr.hasNext()) {
								if (orderCode.equals(itr.next().getOrderCode())) {
									itr.remove();
								}
							}
							
							//notifyDataSetChanged();
							notifyDataSetChanged();
						
						}
					})
					.errorListener(new XErrorListener() {
						
						@Override
						public void onErrorResponse(Exception exception, int code, String msg) {
							 
							
						}
					})
					.build();
			
			HttpRequest.getDefaultRequestQueue().add(request);
		
	}
	/**
	 * 查看物流
	 * @param 订单号
	 */
	private void searchEms(String orderCode)
	{
		
			Intent intent=new Intent(App.ctx,EmsActivity.class);
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			intent.putExtra("ordercode", orderCode);
			App.ctx.startActivity(intent);
		
	}

}
